package analisador;


import java.io.Reader;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.PorterStemFilter;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.util.Version;

public class CustomAnalyzer extends Analyzer {

    private Version v;
    private static Set<String> stopWords;
    private static final String[] STANDARD_STOP_WORDS = {"but", "be", "with", "such",
        "then", "for", "no", "will", "not", "are", "and", "their", "if", "this",
        "on", "into", "a", "or", "there", "in", "that", "they", "was", "is", "it",
        "an", "the", "as", "at", "these", "by", "to", "of"};
    private static final String[] ADDITIONAL_STOP_WORDS = {
        "should", "would", "from", "i", "s", "it", "his", "has","have", "he",
        "she", "her", "been", "being", "aren't", "isn't", "hasn't", "haven't",
        "don't", "won't", "i'll", "i've", "i's", "you're"
        };

    static {
        List<String> allStopWords = new ArrayList<String>(Arrays.asList(ADDITIONAL_STOP_WORDS));
        allStopWords.addAll(Arrays.asList(STANDARD_STOP_WORDS));
        stopWords = new HashSet<String>(allStopWords);
    }

    public CustomAnalyzer(Version v) {
        this.v = v;

    }

    @Override
    public TokenStream tokenStream(String string, Reader reader) {
        TokenStream tokenizer = new StandardTokenizer(v, reader);
        tokenizer = new LowerCaseFilter(v, tokenizer);
        tokenizer = new StopFilter(v, tokenizer, stopWords, true);
        return new PorterStemFilter(tokenizer);
    }
;
}
